class Solution(object):
    def searchMatrix(self, matrix, target):
        """
        :type matrix: List[List[int]]
        :type target: int
        :rtype: bool
        """
        # 关键从左下或者右上开始找
        m = len(matrix)
        n = len(matrix[0]) if m else 0
        if m == 0:
            return False
        row = m-1
        col = 0
        while row >= 0 and col < n:
            # print('row is %d, col is %d' % (row, col))
            if matrix[row][col] == target:
                return True
            elif matrix[row][col] < target:
                col += 1
            else:
                row -= 1
        return False